const requireDirectory = require('require-directory')
const Router = require('koa-router')

class initManager {
    static initCore(app) {
        initManager.app = app
        //路由载入
        initManager.initLoadEouters()
    }
    static initLoadEouters() {
        requireDirectory(module, process.cwd() + '/app/api', {
            visit: whenLoadModule
        })
    }
}

function whenLoadModule(obj) {
    if (obj instanceof Router) {
        initManager.app.use(obj.routes())
    }
}

module.exports = initManager